import { defineConfig, loadEnv } from 'vite';
import path from 'path';
import vue from '@vitejs/plugin-vue';
import eslintPlugin from 'vite-plugin-eslint';
import AutoImport from 'unplugin-auto-import/vite';
// import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import ElementPlus from 'unplugin-element-plus/vite';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
	const env = loadEnv(mode, process.cwd(), '');
	return {
		base: '/',
		//一下为新添加的内容
		envPrefix: ['VITE', 'VUE'], // 环境变量前缀,默认只会暴露VITE开头变量，定义后可暴露VUE开头变量
		define: {
			'process.env': env,
		},
		resolve: {
			alias: {
				'@': `${path.resolve(__dirname, 'src')}/`,
			},
		},
		// css: {
		// 	preprocessorOptions: {
		// 		scss: {
		// 			additionalData: '@use "@/style.scss" as *;',
		// 		},
		// 	},
		// },
		plugins: [
			// ElementPlus({
			//   useSource: true
			// }),
			vue(),
			AutoImport({
				resolvers: [
					ElementPlusResolver({
						// 自动引入修改主题色添加这一行，使用预处理样式，不添加将会导致使用ElMessage，ElNotification等组件时默认的主题色会覆盖自定义的主题色
						importStyle: 'sass',
					}),
				],
			}),
			eslintPlugin({
				include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
			}),
			ElementPlus({
				useSource: true,
			}),
		],
		server: {
			open: true,
			proxy: {
				'/api': {
					target: 'http://localhost:9527',
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/api/, ''),
				},
			},
			hmr: true, // 热更新是否开启
			port: 21522,
			host: true,
		},
		build: {
			assetsDir: './static/front/',
		},
	};
});
